import config
import os
import sys
import argparse

from utils.custom_log import log_start
logger = log_start('main')

def parse_args():
    """
    获取参数
    """
    content = """交易机器人
    demo:  python3 robot.py  
    """
    parser = argparse.ArgumentParser(
        usage="ATA",
        description=content,
        add_help=False,
        formatter_class=lambda prog: argparse.RawTextHelpFormatter(
            prog, max_help_position=50)
    )
    parser.add_argument("--help",
                        action="help",
                        help="查看帮助信息")
    parser.add_argument("-p",'--passphrase',
                        help='passphrase')
    parser.add_argument("-k",'--api_key',
                        help='api_key')
    parser.add_argument("-s",'--secret_key',
                        help='secret_key')
    parser.add_argument('--platform',
                        help='platform')
    args = parser.parse_args()
    return args



if __name__ == '__main__':
    info='''
    > Robot Began to running 
    '''
    print(info)

    if os.path.exists('config.py') and hasattr(config,"configs"):
        if 'okex' in config.configs:
            config_dict = config.configs["okex"]
            import api.okex_client as client
            con = client.OkexAPI(config_dict)

    elif len(sys.argv) > 1:
        args = parse_args()
        config_dict = vars(args)
        import api.okex_client as client
        if 'okex' == config_dict['platform']:
            con = client.OkexAPI(config_dict)

    else:
        print("没有提供所需的api认证信息 !!!")
        sys.exit(1)


    con.get_wallet() # 打印钱包

    # s = con.currencies()
    # print(s.json()['data'])

        
    
    
    # ### 打印基本数据 ###
   
    # con.account_position_risk() # 打印已购买的币
    # con.leverage_info("SHIB-USDT-SWAP","isolated") # 获取当前刚刚倍数
     
    
    ### 创建订单 ###
    # instId="BTT-USDT-SWAP"
    # tdMode="isolated"
    # side = "sell"
    # ordType = "market"
    # posSide = "short"
    # sz="10000"
    # ret  = con.order(instId,tdMode,side,posSide,ordType,sz)
    # print(ret.json())

    ### 市价仓位全平  ###
    ret = con.close_position("BTT-USDT-SWAP","isolated")
    print(ret)

    

    